package com.kelvin.paopao.module.chat.kefu;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.kelvin.paopao.R;
import com.kelvin.paopao.adapter.KefuAdapter;
import com.kelvin.paopao.api.responseBean.KefuModel;
import com.kelvin.paopao.module.base.BaseActivity;
import com.kelvin.paopao.module.chat.chat.ChatActivity;
import com.kelvin.paopao.widgets.CustomToolbar;

import java.io.Serializable;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2017/7/18.
 */

public class KefuActivity extends BaseActivity {
    @BindView(R.id.custom_toolbar)
    CustomToolbar customToolbar;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;

    private List<KefuModel> kefuModelList;


    private KefuAdapter adapter;
    private LinearLayoutManager manager;


    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_kefu;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {
        customToolbar.showBackIcon(this);

        kefuModelList = (List<KefuModel>) getIntent().getSerializableExtra("kefu");
        adapter = new KefuAdapter(this);

        manager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                ChatActivity.launch(KefuActivity.this,
                        ((KefuModel) (adapter.getData().get(position))).getUser_no());
            }
        });
        adapter.setNewData(kefuModelList);
    }

    @Override
    protected void updateViews(boolean isRefresh) {

    }

    public static void launch(Context context, List<KefuModel> kefuModelList) {
        Intent intent = new Intent(context, KefuActivity.class);
        intent.putExtra("kefu", (Serializable) kefuModelList);
        context.startActivity(intent);
    }

}
